
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/categories.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:24:04 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Category Theory &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
    <script src="../_static/jquery.js"></script>
    <script src="../_static/underscore.js"></script>
    <script src="../_static/doctools.js"></script>
    <script src="../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../live.sympy.org/static/live-sphinx.js"></script>
    <script async="async" src="../../../cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest8331.js?config=TeX-AMS_HTML-full"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]]}})</script>
    
    <link rel="shortcut icon" href="../_static/sympy-notailtext-favicon.ico"/>
    <link href="categories.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Code Generation" href="codegen.html" />
    <link rel="prev" title="Calculus" href="calculus/index.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="codegen.html" title="Code Generation"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="calculus/index.html" title="Calculus"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">SymPy Modules Reference</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Category Theory</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="category-theory">
<h1>Category Theory<a class="headerlink" href="#category-theory" title="Permalink to this headline">¶</a></h1>
<section id="introduction">
<h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
<p>The category theory module for SymPy will allow manipulating diagrams
within a single category, including drawing them in TikZ and deciding
whether they are commutative or not.</p>
<p>The general reference work this module tries to follow is</p>
<dl class="citation">
<dt class="label" id="joyofcats"><span class="brackets">JoyOfCats</span></dt>
<dd><ol class="upperalpha simple" start="10">
<li><p>Adamek, H. Herrlich. G. E. Strecker: Abstract and Concrete Categories. The Joy of Cats.</p></li>
</ol>
</dd>
</dl>
<p>The latest version of this book should be available for free download
from</p>
<p><a class="reference external" href="http://katmat.math.uni-bremen.de/acc/acc.pdf">katmat.math.uni-bremen.de/acc/acc.pdf</a></p>
<p>The module is still in its pre-embryonic stage.</p>
</section>
<section id="module-sympy.categories">
<span id="base-class-reference"></span><h2>Base Class Reference<a class="headerlink" href="#module-sympy.categories" title="Permalink to this headline">¶</a></h2>
<p>This section lists the classes which implement some of the basic
notions in category theory: objects, morphisms, categories, and
diagrams.</p>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.categories.Object">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.categories.</span></span><span class="sig-name descname"><span class="pre">Object</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">assumptions</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/categories/baseclasses.py#L26-L36"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.categories.Object" title="Permalink to this definition">¶</a></dt>
<dd><p>The base class for any kind of object in an abstract category.</p>
<p class="rubric">Explanation</p>
<p>While technically any instance of <a class="reference internal" href="core.html#sympy.core.basic.Basic" title="sympy.core.basic.Basic"><code class="xref py py-class docutils literal notranslate"><span class="pre">Basic</span></code></a> will do, this
class is the recommended way to create abstract objects in
abstract categories.</p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.categories.Morphism">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.categories.</span></span><span class="sig-name descname"><span class="pre">Morphism</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">domain</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">codomain</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/categories/baseclasses.py#L39-L143"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.categories.Morphism" title="Permalink to this definition">¶</a></dt>
<dd><p>The base class for any morphism in an abstract category.</p>
<p class="rubric">Explanation</p>
<p>In abstract categories, a morphism is an arrow between two
category objects.  The object where the arrow starts is called the
domain, while the object where the arrow ends is called the
codomain.</p>
<p>Two morphisms between the same pair of objects are considered to
be the same morphisms.  To distinguish between morphisms between
the same objects use <a class="reference internal" href="#sympy.categories.NamedMorphism" title="sympy.categories.NamedMorphism"><code class="xref py py-class docutils literal notranslate"><span class="pre">NamedMorphism</span></code></a>.</p>
<p>It is prohibited to instantiate this class.  Use one of the
derived classes instead.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.categories.IdentityMorphism" title="sympy.categories.IdentityMorphism"><code class="xref py py-obj docutils literal notranslate"><span class="pre">IdentityMorphism</span></code></a>, <a class="reference internal" href="#sympy.categories.NamedMorphism" title="sympy.categories.NamedMorphism"><code class="xref py py-obj docutils literal notranslate"><span class="pre">NamedMorphism</span></code></a>, <a class="reference internal" href="#sympy.categories.CompositeMorphism" title="sympy.categories.CompositeMorphism"><code class="xref py py-obj docutils literal notranslate"><span class="pre">CompositeMorphism</span></code></a></p>
</div>
<dl class="py property">
<dt class="sig sig-object py" id="sympy.categories.Morphism.codomain">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">codomain</span></span><a class="headerlink" href="#sympy.categories.Morphism.codomain" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the codomain of the morphism.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">codomain</span>
<span class="go">Object(&quot;B&quot;)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.categories.Morphism.compose">
<span class="sig-name descname"><span class="pre">compose</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/categories/baseclasses.py#L103-L128"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.categories.Morphism.compose" title="Permalink to this definition">¶</a></dt>
<dd><p>Composes self with the supplied morphism.</p>
<p>The order of elements in the composition is the usual order,
i.e., to construct <span class="math notranslate nohighlight">\(g\circ f\)</span> use <code class="docutils literal notranslate"><span class="pre">g.compose(f)</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;C&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">*</span> <span class="n">f</span>
<span class="go">CompositeMorphism((NamedMorphism(Object(&quot;A&quot;), Object(&quot;B&quot;), &quot;f&quot;),</span>
<span class="go">NamedMorphism(Object(&quot;B&quot;), Object(&quot;C&quot;), &quot;g&quot;)))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">g</span> <span class="o">*</span> <span class="n">f</span><span class="p">)</span><span class="o">.</span><span class="n">domain</span>
<span class="go">Object(&quot;A&quot;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">g</span> <span class="o">*</span> <span class="n">f</span><span class="p">)</span><span class="o">.</span><span class="n">codomain</span>
<span class="go">Object(&quot;C&quot;)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.categories.Morphism.domain">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">domain</span></span><a class="headerlink" href="#sympy.categories.Morphism.domain" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the domain of the morphism.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">domain</span>
<span class="go">Object(&quot;A&quot;)</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.categories.NamedMorphism">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.categories.</span></span><span class="sig-name descname"><span class="pre">NamedMorphism</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">domain</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">codomain</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/categories/baseclasses.py#L183-L236"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.categories.NamedMorphism" title="Permalink to this definition">¶</a></dt>
<dd><p>Represents a morphism which has a name.</p>
<p class="rubric">Explanation</p>
<p>Names are used to distinguish between morphisms which have the
same domain and codomain: two named morphisms are equal if they
have the same domains, codomains, and names.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span>
<span class="go">NamedMorphism(Object(&quot;A&quot;), Object(&quot;B&quot;), &quot;f&quot;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">name</span>
<span class="go">&#39;f&#39;</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.categories.Morphism" title="sympy.categories.Morphism"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Morphism</span></code></a></p>
</div>
<dl class="py property">
<dt class="sig sig-object py" id="sympy.categories.NamedMorphism.name">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">name</span></span><a class="headerlink" href="#sympy.categories.NamedMorphism.name" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the name of the morphism.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">name</span>
<span class="go">&#39;f&#39;</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.categories.CompositeMorphism">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.categories.</span></span><span class="sig-name descname"><span class="pre">CompositeMorphism</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">components</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/categories/baseclasses.py#L239-L423"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.categories.CompositeMorphism" title="Permalink to this definition">¶</a></dt>
<dd><p>Represents a morphism which is a composition of other morphisms.</p>
<p class="rubric">Explanation</p>
<p>Two composite morphisms are equal if the morphisms they were
obtained from (components) are the same and were listed in the
same order.</p>
<p>The arguments to the constructor for this class should be listed
in diagram order: to obtain the composition <span class="math notranslate nohighlight">\(g\circ f\)</span> from the
instances of <a class="reference internal" href="#sympy.categories.Morphism" title="sympy.categories.Morphism"><code class="xref py py-class docutils literal notranslate"><span class="pre">Morphism</span></code></a> <code class="docutils literal notranslate"><span class="pre">g</span></code> and <code class="docutils literal notranslate"><span class="pre">f</span></code> use
<code class="docutils literal notranslate"><span class="pre">CompositeMorphism(f,</span> <span class="pre">g)</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span><span class="p">,</span> <span class="n">CompositeMorphism</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;C&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">*</span> <span class="n">f</span>
<span class="go">CompositeMorphism((NamedMorphism(Object(&quot;A&quot;), Object(&quot;B&quot;), &quot;f&quot;),</span>
<span class="go">NamedMorphism(Object(&quot;B&quot;), Object(&quot;C&quot;), &quot;g&quot;)))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">CompositeMorphism</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">)</span> <span class="o">==</span> <span class="n">g</span> <span class="o">*</span> <span class="n">f</span>
<span class="go">True</span>
</pre></div>
</div>
<dl class="py property">
<dt class="sig sig-object py" id="sympy.categories.CompositeMorphism.codomain">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">codomain</span></span><a class="headerlink" href="#sympy.categories.CompositeMorphism.codomain" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the codomain of this composite morphism.</p>
<p>The codomain of the composite morphism is the codomain of its
last component.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;C&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">g</span> <span class="o">*</span> <span class="n">f</span><span class="p">)</span><span class="o">.</span><span class="n">codomain</span>
<span class="go">Object(&quot;C&quot;)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.categories.CompositeMorphism.components">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">components</span></span><a class="headerlink" href="#sympy.categories.CompositeMorphism.components" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the components of this composite morphism.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;C&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">g</span> <span class="o">*</span> <span class="n">f</span><span class="p">)</span><span class="o">.</span><span class="n">components</span>
<span class="go">(NamedMorphism(Object(&quot;A&quot;), Object(&quot;B&quot;), &quot;f&quot;),</span>
<span class="go">NamedMorphism(Object(&quot;B&quot;), Object(&quot;C&quot;), &quot;g&quot;))</span>
</pre></div>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.categories.CompositeMorphism.domain">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">domain</span></span><a class="headerlink" href="#sympy.categories.CompositeMorphism.domain" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the domain of this composite morphism.</p>
<p>The domain of the composite morphism is the domain of its
first component.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;C&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">g</span> <span class="o">*</span> <span class="n">f</span><span class="p">)</span><span class="o">.</span><span class="n">domain</span>
<span class="go">Object(&quot;A&quot;)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.categories.CompositeMorphism.flatten">
<span class="sig-name descname"><span class="pre">flatten</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">new_name</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/categories/baseclasses.py#L397-L423"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.categories.CompositeMorphism.flatten" title="Permalink to this definition">¶</a></dt>
<dd><p>Forgets the composite structure of this morphism.</p>
<p class="rubric">Explanation</p>
<p>If <code class="docutils literal notranslate"><span class="pre">new_name</span></code> is not empty, returns a <a class="reference internal" href="#sympy.categories.NamedMorphism" title="sympy.categories.NamedMorphism"><code class="xref py py-class docutils literal notranslate"><span class="pre">NamedMorphism</span></code></a>
with the supplied name, otherwise returns a <a class="reference internal" href="#sympy.categories.Morphism" title="sympy.categories.Morphism"><code class="xref py py-class docutils literal notranslate"><span class="pre">Morphism</span></code></a>.
In both cases the domain of the new morphism is the domain of
this composite morphism and the codomain of the new morphism
is the codomain of this composite morphism.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;C&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">g</span> <span class="o">*</span> <span class="n">f</span><span class="p">)</span><span class="o">.</span><span class="n">flatten</span><span class="p">(</span><span class="s2">&quot;h&quot;</span><span class="p">)</span>
<span class="go">NamedMorphism(Object(&quot;A&quot;), Object(&quot;C&quot;), &quot;h&quot;)</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.categories.IdentityMorphism">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.categories.</span></span><span class="sig-name descname"><span class="pre">IdentityMorphism</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">domain</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/categories/baseclasses.py#L146-L180"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.categories.IdentityMorphism" title="Permalink to this definition">¶</a></dt>
<dd><p>Represents an identity morphism.</p>
<p class="rubric">Explanation</p>
<p>An identity morphism is a morphism with equal domain and codomain,
which acts as an identity with respect to composition.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span><span class="p">,</span> <span class="n">IdentityMorphism</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">id_A</span> <span class="o">=</span> <span class="n">IdentityMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">id_B</span> <span class="o">=</span> <span class="n">IdentityMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">*</span> <span class="n">id_A</span> <span class="o">==</span> <span class="n">f</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">id_B</span> <span class="o">*</span> <span class="n">f</span> <span class="o">==</span> <span class="n">f</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.categories.Morphism" title="sympy.categories.Morphism"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Morphism</span></code></a></p>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.categories.Category">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.categories.</span></span><span class="sig-name descname"><span class="pre">Category</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">objects</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">EmptySet</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">commutative_diagrams</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">EmptySet</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/categories/baseclasses.py#L426-L560"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.categories.Category" title="Permalink to this definition">¶</a></dt>
<dd><p>An (abstract) category.</p>
<p class="rubric">Explanation</p>
<p>A category [JoyOfCats] is a quadruple <span class="math notranslate nohighlight">\(\mbox{K} = (O, \hom, id,
\circ)\)</span> consisting of</p>
<ul class="simple">
<li><p>a (set-theoretical) class <span class="math notranslate nohighlight">\(O\)</span>, whose members are called
<span class="math notranslate nohighlight">\(K\)</span>-objects,</p></li>
<li><p>for each pair <span class="math notranslate nohighlight">\((A, B)\)</span> of <span class="math notranslate nohighlight">\(K\)</span>-objects, a set <span class="math notranslate nohighlight">\(\hom(A, B)\)</span> whose
members are called <span class="math notranslate nohighlight">\(K\)</span>-morphisms from <span class="math notranslate nohighlight">\(A\)</span> to <span class="math notranslate nohighlight">\(B\)</span>,</p></li>
<li><p>for a each <span class="math notranslate nohighlight">\(K\)</span>-object <span class="math notranslate nohighlight">\(A\)</span>, a morphism <span class="math notranslate nohighlight">\(id:A\rightarrow A\)</span>,
called the <span class="math notranslate nohighlight">\(K\)</span>-identity of <span class="math notranslate nohighlight">\(A\)</span>,</p></li>
<li><p>a composition law <span class="math notranslate nohighlight">\(\circ\)</span> associating with every <span class="math notranslate nohighlight">\(K\)</span>-morphisms
<span class="math notranslate nohighlight">\(f:A\rightarrow B\)</span> and <span class="math notranslate nohighlight">\(g:B\rightarrow C\)</span> a <span class="math notranslate nohighlight">\(K\)</span>-morphism <span class="math notranslate nohighlight">\(g\circ
f:A\rightarrow C\)</span>, called the composite of <span class="math notranslate nohighlight">\(f\)</span> and <span class="math notranslate nohighlight">\(g\)</span>.</p></li>
</ul>
<p>Composition is associative, <span class="math notranslate nohighlight">\(K\)</span>-identities are identities with
respect to composition, and the sets <span class="math notranslate nohighlight">\(\hom(A, B)\)</span> are pairwise
disjoint.</p>
<p>This class knows nothing about its objects and morphisms.
Concrete cases of (abstract) categories should be implemented as
classes derived from this one.</p>
<p>Certain instances of <a class="reference internal" href="#sympy.categories.Diagram" title="sympy.categories.Diagram"><code class="xref py py-class docutils literal notranslate"><span class="pre">Diagram</span></code></a> can be asserted to be
commutative in a <a class="reference internal" href="#sympy.categories.Category" title="sympy.categories.Category"><code class="xref py py-class docutils literal notranslate"><span class="pre">Category</span></code></a> by supplying the argument
<code class="docutils literal notranslate"><span class="pre">commutative_diagrams</span></code> in the constructor.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span><span class="p">,</span> <span class="n">Diagram</span><span class="p">,</span> <span class="n">Category</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">FiniteSet</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;C&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">K</span> <span class="o">=</span> <span class="n">Category</span><span class="p">(</span><span class="s2">&quot;K&quot;</span><span class="p">,</span> <span class="n">commutative_diagrams</span><span class="o">=</span><span class="p">[</span><span class="n">d</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">K</span><span class="o">.</span><span class="n">commutative_diagrams</span> <span class="o">==</span> <span class="n">FiniteSet</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.categories.Diagram" title="sympy.categories.Diagram"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Diagram</span></code></a></p>
</div>
<dl class="py property">
<dt class="sig sig-object py" id="sympy.categories.Category.commutative_diagrams">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">commutative_diagrams</span></span><a class="headerlink" href="#sympy.categories.Category.commutative_diagrams" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the <a class="reference internal" href="sets.html#sympy.sets.sets.FiniteSet" title="sympy.sets.sets.FiniteSet"><code class="xref py py-class docutils literal notranslate"><span class="pre">FiniteSet</span></code></a> of diagrams which are known to
be commutative in this category.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span><span class="p">,</span> <span class="n">Diagram</span><span class="p">,</span> <span class="n">Category</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">FiniteSet</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;C&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">K</span> <span class="o">=</span> <span class="n">Category</span><span class="p">(</span><span class="s2">&quot;K&quot;</span><span class="p">,</span> <span class="n">commutative_diagrams</span><span class="o">=</span><span class="p">[</span><span class="n">d</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">K</span><span class="o">.</span><span class="n">commutative_diagrams</span> <span class="o">==</span> <span class="n">FiniteSet</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.categories.Category.name">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">name</span></span><a class="headerlink" href="#sympy.categories.Category.name" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the name of this category.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Category</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">K</span> <span class="o">=</span> <span class="n">Category</span><span class="p">(</span><span class="s2">&quot;K&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">K</span><span class="o">.</span><span class="n">name</span>
<span class="go">&#39;K&#39;</span>
</pre></div>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.categories.Category.objects">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">objects</span></span><a class="headerlink" href="#sympy.categories.Category.objects" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the class of objects of this category.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">Category</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">FiniteSet</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">K</span> <span class="o">=</span> <span class="n">Category</span><span class="p">(</span><span class="s2">&quot;K&quot;</span><span class="p">,</span> <span class="n">FiniteSet</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">K</span><span class="o">.</span><span class="n">objects</span>
<span class="go">Class({Object(&quot;A&quot;), Object(&quot;B&quot;)})</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.categories.Diagram">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.categories.</span></span><span class="sig-name descname"><span class="pre">Diagram</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/categories/baseclasses.py#L563-L979"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.categories.Diagram" title="Permalink to this definition">¶</a></dt>
<dd><p>Represents a diagram in a certain category.</p>
<p class="rubric">Explanation</p>
<p>Informally, a diagram is a collection of objects of a category and
certain morphisms between them.  A diagram is still a monoid with
respect to morphism composition; i.e., identity morphisms, as well
as all composites of morphisms included in the diagram belong to
the diagram.  For a more formal approach to this notion see
[Pare1970].</p>
<p>The components of composite morphisms are also added to the
diagram.  No properties are assigned to such morphisms by default.</p>
<p>A commutative diagram is often accompanied by a statement of the
following kind: “if such morphisms with such properties exist,
then such morphisms which such properties exist and the diagram is
commutative”.  To represent this, an instance of <a class="reference internal" href="#sympy.categories.Diagram" title="sympy.categories.Diagram"><code class="xref py py-class docutils literal notranslate"><span class="pre">Diagram</span></code></a>
includes a collection of morphisms which are the premises and
another collection of conclusions.  <code class="docutils literal notranslate"><span class="pre">premises</span></code> and
<code class="docutils literal notranslate"><span class="pre">conclusions</span></code> associate morphisms belonging to the corresponding
categories with the <a class="reference internal" href="sets.html#sympy.sets.sets.FiniteSet" title="sympy.sets.sets.FiniteSet"><code class="xref py py-class docutils literal notranslate"><span class="pre">FiniteSet</span></code></a>’s of their properties.</p>
<p>The set of properties of a composite morphism is the intersection
of the sets of properties of its components.  The domain and
codomain of a conclusion morphism should be among the domains and
codomains of the morphisms listed as the premises of a diagram.</p>
<p>No checks are carried out of whether the supplied object and
morphisms do belong to one and the same category.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span><span class="p">,</span> <span class="n">Diagram</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">pprint</span><span class="p">,</span> <span class="n">default_sort_key</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;C&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">premises_keys</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">premises</span><span class="o">.</span><span class="n">keys</span><span class="p">(),</span> <span class="n">key</span><span class="o">=</span><span class="n">default_sort_key</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">premises_keys</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">[g*f:A--&gt;C, id:A--&gt;A, id:B--&gt;B, id:C--&gt;C, f:A--&gt;B, g:B--&gt;C]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">premises</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">{g*f:A--&gt;C: EmptySet, id:A--&gt;A: EmptySet, id:B--&gt;B: EmptySet, id:C--&gt;C: EmptyS</span>
<span class="go">et, f:A--&gt;B: EmptySet, g:B--&gt;C: EmptySet}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">],</span> <span class="p">{</span><span class="n">g</span> <span class="o">*</span> <span class="n">f</span><span class="p">:</span> <span class="s2">&quot;unique&quot;</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">conclusions</span><span class="p">,</span><span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">{g*f:A--&gt;C: {unique}}</span>
</pre></div>
</div>
<p class="rubric">References</p>
<p>[Pare1970] B. Pareigis: Categories and functors.  Academic Press,
1970.</p>
<dl class="py property">
<dt class="sig sig-object py" id="sympy.categories.Diagram.conclusions">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">conclusions</span></span><a class="headerlink" href="#sympy.categories.Diagram.conclusions" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the conclusions of this diagram.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">IdentityMorphism</span><span class="p">,</span> <span class="n">Diagram</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">FiniteSet</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;C&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">IdentityMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">)</span> <span class="ow">in</span> <span class="n">d</span><span class="o">.</span><span class="n">premises</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">*</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">d</span><span class="o">.</span><span class="n">premises</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">],</span> <span class="p">{</span><span class="n">g</span> <span class="o">*</span> <span class="n">f</span><span class="p">:</span> <span class="s2">&quot;unique&quot;</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">.</span><span class="n">conclusions</span><span class="p">[</span><span class="n">g</span> <span class="o">*</span> <span class="n">f</span><span class="p">]</span> <span class="o">==</span> <span class="n">FiniteSet</span><span class="p">(</span><span class="s2">&quot;unique&quot;</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.categories.Diagram.hom">
<span class="sig-name descname"><span class="pre">hom</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">A</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">B</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/categories/baseclasses.py#L867-L901"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.categories.Diagram.hom" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a 2-tuple of sets of morphisms between objects <code class="docutils literal notranslate"><span class="pre">A</span></code> and
<code class="docutils literal notranslate"><span class="pre">B</span></code>: one set of morphisms listed as premises, and the other set
of morphisms listed as conclusions.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span><span class="p">,</span> <span class="n">Diagram</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">pretty</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;C&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">],</span> <span class="p">{</span><span class="n">g</span> <span class="o">*</span> <span class="n">f</span><span class="p">:</span> <span class="s2">&quot;unique&quot;</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">pretty</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">hom</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">C</span><span class="p">),</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">))</span>
<span class="go">({g*f:A--&gt;C}, {g*f:A--&gt;C})</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.categories.Object" title="sympy.categories.Object"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Object</span></code></a>, <a class="reference internal" href="#sympy.categories.Morphism" title="sympy.categories.Morphism"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Morphism</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.categories.Diagram.is_subdiagram">
<span class="sig-name descname"><span class="pre">is_subdiagram</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">diagram</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/categories/baseclasses.py#L903-L939"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.categories.Diagram.is_subdiagram" title="Permalink to this definition">¶</a></dt>
<dd><p>Checks whether <code class="docutils literal notranslate"><span class="pre">diagram</span></code> is a subdiagram of <code class="docutils literal notranslate"><span class="pre">self</span></code>.
Diagram <span class="math notranslate nohighlight">\(D'\)</span> is a subdiagram of <span class="math notranslate nohighlight">\(D\)</span> if all premises
(conclusions) of <span class="math notranslate nohighlight">\(D'\)</span> are contained in the premises
(conclusions) of <span class="math notranslate nohighlight">\(D\)</span>.  The morphisms contained
both in <span class="math notranslate nohighlight">\(D'\)</span> and <span class="math notranslate nohighlight">\(D\)</span> should have the same properties for <span class="math notranslate nohighlight">\(D'\)</span>
to be a subdiagram of <span class="math notranslate nohighlight">\(D\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span><span class="p">,</span> <span class="n">Diagram</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;C&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">],</span> <span class="p">{</span><span class="n">g</span> <span class="o">*</span> <span class="n">f</span><span class="p">:</span> <span class="s2">&quot;unique&quot;</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d1</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">.</span><span class="n">is_subdiagram</span><span class="p">(</span><span class="n">d1</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d1</span><span class="o">.</span><span class="n">is_subdiagram</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.categories.Diagram.objects">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">objects</span></span><a class="headerlink" href="#sympy.categories.Diagram.objects" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the <a class="reference internal" href="sets.html#sympy.sets.sets.FiniteSet" title="sympy.sets.sets.FiniteSet"><code class="xref py py-class docutils literal notranslate"><span class="pre">FiniteSet</span></code></a> of objects that appear in this
diagram.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span><span class="p">,</span> <span class="n">Diagram</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;C&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">.</span><span class="n">objects</span>
<span class="go">{Object(&quot;A&quot;), Object(&quot;B&quot;), Object(&quot;C&quot;)}</span>
</pre></div>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.categories.Diagram.premises">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">premises</span></span><a class="headerlink" href="#sympy.categories.Diagram.premises" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the premises of this diagram.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">IdentityMorphism</span><span class="p">,</span> <span class="n">Diagram</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">pretty</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">id_A</span> <span class="o">=</span> <span class="n">IdentityMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">id_B</span> <span class="o">=</span> <span class="n">IdentityMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">pretty</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">premises</span><span class="p">,</span> <span class="n">use_unicode</span><span class="o">=</span><span class="kc">False</span><span class="p">))</span>
<span class="go">{id:A--&gt;A: EmptySet, id:B--&gt;B: EmptySet, f:A--&gt;B: EmptySet}</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.categories.Diagram.subdiagram_from_objects">
<span class="sig-name descname"><span class="pre">subdiagram_from_objects</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">objects</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/categories/baseclasses.py#L941-L979"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.categories.Diagram.subdiagram_from_objects" title="Permalink to this definition">¶</a></dt>
<dd><p>If <code class="docutils literal notranslate"><span class="pre">objects</span></code> is a subset of the objects of <code class="docutils literal notranslate"><span class="pre">self</span></code>, returns
a diagram which has as premises all those premises of <code class="docutils literal notranslate"><span class="pre">self</span></code>
which have a domains and codomains in <code class="docutils literal notranslate"><span class="pre">objects</span></code>, likewise
for conclusions.  Properties are preserved.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span><span class="p">,</span> <span class="n">Diagram</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">FiniteSet</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;C&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">],</span> <span class="p">{</span><span class="n">f</span><span class="p">:</span> <span class="s2">&quot;unique&quot;</span><span class="p">,</span> <span class="n">g</span><span class="o">*</span><span class="n">f</span><span class="p">:</span> <span class="s2">&quot;veryunique&quot;</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d1</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">subdiagram_from_objects</span><span class="p">(</span><span class="n">FiniteSet</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d1</span> <span class="o">==</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">],</span> <span class="p">{</span><span class="n">f</span><span class="p">:</span> <span class="s2">&quot;unique&quot;</span><span class="p">})</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</section>
<section id="module-sympy.categories.diagram_drawing">
<span id="diagram-drawing"></span><h2>Diagram Drawing<a class="headerlink" href="#module-sympy.categories.diagram_drawing" title="Permalink to this headline">¶</a></h2>
<p>This section lists the classes which allow automatic drawing of
diagrams.</p>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.categories.diagram_drawing.DiagramGrid">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.categories.diagram_drawing.</span></span><span class="sig-name descname"><span class="pre">DiagramGrid</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">diagram</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">groups</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">hints</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/categories/diagram_drawing.py#L176-L1361"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.categories.diagram_drawing.DiagramGrid" title="Permalink to this definition">¶</a></dt>
<dd><p>Constructs and holds the fitting of the diagram into a grid.</p>
<p class="rubric">Explanation</p>
<p>The mission of this class is to analyse the structure of the
supplied diagram and to place its objects on a grid such that,
when the objects and the morphisms are actually drawn, the diagram
would be “readable”, in the sense that there will not be many
intersections of moprhisms.  This class does not perform any
actual drawing.  It does strive nevertheless to offer sufficient
metadata to draw a diagram.</p>
<p>Consider the following simple diagram.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Diagram</span><span class="p">,</span> <span class="n">DiagramGrid</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">pprint</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;C&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diagram</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">])</span>
</pre></div>
</div>
<p>The simplest way to have a diagram laid out is the following:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">grid</span> <span class="o">=</span> <span class="n">DiagramGrid</span><span class="p">(</span><span class="n">diagram</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">grid</span><span class="o">.</span><span class="n">width</span><span class="p">,</span> <span class="n">grid</span><span class="o">.</span><span class="n">height</span><span class="p">)</span>
<span class="go">(2, 2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">grid</span><span class="p">)</span>
<span class="go">A  B</span>

<span class="go">   C</span>
</pre></div>
</div>
<p>Sometimes one sees the diagram as consisting of logical groups.
One can advise <code class="docutils literal notranslate"><span class="pre">DiagramGrid</span></code> as to such groups by employing the
<code class="docutils literal notranslate"><span class="pre">groups</span></code> keyword argument.</p>
<p>Consider the following diagram:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;D&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">h</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">A</span><span class="p">,</span> <span class="s2">&quot;h&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">k</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;k&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diagram</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">,</span> <span class="n">h</span><span class="p">,</span> <span class="n">k</span><span class="p">])</span>
</pre></div>
</div>
<p>Lay it out with generic layout:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">grid</span> <span class="o">=</span> <span class="n">DiagramGrid</span><span class="p">(</span><span class="n">diagram</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">grid</span><span class="p">)</span>
<span class="go">A  B  D</span>

<span class="go">   C</span>
</pre></div>
</div>
<p>Now, we can group the objects <span class="math notranslate nohighlight">\(A\)</span> and <span class="math notranslate nohighlight">\(D\)</span> to have them near one
another:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">grid</span> <span class="o">=</span> <span class="n">DiagramGrid</span><span class="p">(</span><span class="n">diagram</span><span class="p">,</span> <span class="n">groups</span><span class="o">=</span><span class="p">[[</span><span class="n">A</span><span class="p">,</span> <span class="n">D</span><span class="p">],</span> <span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">grid</span><span class="p">)</span>
<span class="go">B     C</span>

<span class="go">A  D</span>
</pre></div>
</div>
<p>Note how the positioning of the other objects changes.</p>
<p>Further indications can be supplied to the constructor of
<a class="reference internal" href="#sympy.categories.diagram_drawing.DiagramGrid" title="sympy.categories.diagram_drawing.DiagramGrid"><code class="xref py py-class docutils literal notranslate"><span class="pre">DiagramGrid</span></code></a> using keyword arguments.  The currently
supported hints are explained in the following paragraphs.</p>
<p><a class="reference internal" href="#sympy.categories.diagram_drawing.DiagramGrid" title="sympy.categories.diagram_drawing.DiagramGrid"><code class="xref py py-class docutils literal notranslate"><span class="pre">DiagramGrid</span></code></a> does not automatically guess which layout
would suit the supplied diagram better.  Consider, for example,
the following linear diagram:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;E&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">h</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">D</span><span class="p">,</span> <span class="s2">&quot;h&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="s2">&quot;i&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diagram</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">,</span> <span class="n">h</span><span class="p">,</span> <span class="n">i</span><span class="p">])</span>
</pre></div>
</div>
<p>When laid out with the generic layout, it does not get to look
linear:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">grid</span> <span class="o">=</span> <span class="n">DiagramGrid</span><span class="p">(</span><span class="n">diagram</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">grid</span><span class="p">)</span>
<span class="go">A  B</span>

<span class="go">   C  D</span>

<span class="go">      E</span>
</pre></div>
</div>
<p>To get it laid out in a line, use <code class="docutils literal notranslate"><span class="pre">layout=&quot;sequential&quot;</span></code>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">grid</span> <span class="o">=</span> <span class="n">DiagramGrid</span><span class="p">(</span><span class="n">diagram</span><span class="p">,</span> <span class="n">layout</span><span class="o">=</span><span class="s2">&quot;sequential&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">grid</span><span class="p">)</span>
<span class="go">A  B  C  D  E</span>
</pre></div>
</div>
<p>One may sometimes need to transpose the resulting layout.  While
this can always be done by hand, <a class="reference internal" href="#sympy.categories.diagram_drawing.DiagramGrid" title="sympy.categories.diagram_drawing.DiagramGrid"><code class="xref py py-class docutils literal notranslate"><span class="pre">DiagramGrid</span></code></a> provides a
hint for that purpose:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">grid</span> <span class="o">=</span> <span class="n">DiagramGrid</span><span class="p">(</span><span class="n">diagram</span><span class="p">,</span> <span class="n">layout</span><span class="o">=</span><span class="s2">&quot;sequential&quot;</span><span class="p">,</span> <span class="n">transpose</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">grid</span><span class="p">)</span>
<span class="go">A</span>

<span class="go">B</span>

<span class="go">C</span>

<span class="go">D</span>

<span class="go">E</span>
</pre></div>
</div>
<p>Separate hints can also be provided for each group.  For an
example, refer to <code class="docutils literal notranslate"><span class="pre">tests/test_drawing.py</span></code>, and see the different
ways in which the five lemma [FiveLemma] can be laid out.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.categories.Diagram" title="sympy.categories.Diagram"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Diagram</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="fivelemma"><span class="brackets"><a class="fn-backref" href="#id1">FiveLemma</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Five_lemma">https://en.wikipedia.org/wiki/Five_lemma</a></p>
</dd>
</dl>
<dl class="py property">
<dt class="sig sig-object py" id="sympy.categories.diagram_drawing.DiagramGrid.height">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">height</span></span><a class="headerlink" href="#sympy.categories.diagram_drawing.DiagramGrid.height" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the number of rows in this diagram layout.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Diagram</span><span class="p">,</span> <span class="n">DiagramGrid</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;C&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diagram</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">grid</span> <span class="o">=</span> <span class="n">DiagramGrid</span><span class="p">(</span><span class="n">diagram</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">grid</span><span class="o">.</span><span class="n">height</span>
<span class="go">2</span>
</pre></div>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.categories.diagram_drawing.DiagramGrid.morphisms">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">morphisms</span></span><a class="headerlink" href="#sympy.categories.diagram_drawing.DiagramGrid.morphisms" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns those morphisms (and their properties) which are
sufficiently meaningful to be drawn.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Diagram</span><span class="p">,</span> <span class="n">DiagramGrid</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;C&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diagram</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">grid</span> <span class="o">=</span> <span class="n">DiagramGrid</span><span class="p">(</span><span class="n">diagram</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">grid</span><span class="o">.</span><span class="n">morphisms</span>
<span class="go">{NamedMorphism(Object(&quot;A&quot;), Object(&quot;B&quot;), &quot;f&quot;): EmptySet,</span>
<span class="go">NamedMorphism(Object(&quot;B&quot;), Object(&quot;C&quot;), &quot;g&quot;): EmptySet}</span>
</pre></div>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.categories.diagram_drawing.DiagramGrid.width">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">width</span></span><a class="headerlink" href="#sympy.categories.diagram_drawing.DiagramGrid.width" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the number of columns in this diagram layout.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Diagram</span><span class="p">,</span> <span class="n">DiagramGrid</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;C&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diagram</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">grid</span> <span class="o">=</span> <span class="n">DiagramGrid</span><span class="p">(</span><span class="n">diagram</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">grid</span><span class="o">.</span><span class="n">width</span>
<span class="go">2</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.categories.diagram_drawing.ArrowStringDescription">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.categories.diagram_drawing.</span></span><span class="sig-name descname"><span class="pre">ArrowStringDescription</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">unit</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">curving</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">curving_amount</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">looping_start</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">looping_end</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">horizontal_direction</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">vertical_direction</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">label_position</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">label</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/categories/diagram_drawing.py#L1364-L1504"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.categories.diagram_drawing.ArrowStringDescription" title="Permalink to this definition">¶</a></dt>
<dd><p>Stores the information necessary for producing an Xy-pic
description of an arrow.</p>
<p>The principal goal of this class is to abstract away the string
representation of an arrow and to also provide the functionality
to produce the actual Xy-pic string.</p>
<p><code class="docutils literal notranslate"><span class="pre">unit</span></code> sets the unit which will be used to specify the amount of
curving and other distances.  <code class="docutils literal notranslate"><span class="pre">horizontal_direction</span></code> should be a
string of <code class="docutils literal notranslate"><span class="pre">&quot;r&quot;</span></code> or <code class="docutils literal notranslate"><span class="pre">&quot;l&quot;</span></code> specifying the horizontal offset of the
target cell of the arrow relatively to the current one.
<code class="docutils literal notranslate"><span class="pre">vertical_direction</span></code> should  specify the vertical offset using a
series of either <code class="docutils literal notranslate"><span class="pre">&quot;d&quot;</span></code> or <code class="docutils literal notranslate"><span class="pre">&quot;u&quot;</span></code>.  <code class="docutils literal notranslate"><span class="pre">label_position</span></code> should be
either <code class="docutils literal notranslate"><span class="pre">&quot;^&quot;</span></code>, <code class="docutils literal notranslate"><span class="pre">&quot;_&quot;</span></code>,  or <code class="docutils literal notranslate"><span class="pre">&quot;|&quot;</span></code> to specify that the label should
be positioned above the arrow, below the arrow or just over the arrow,
in a break.  Note that the notions “above” and “below” are relative
to arrow direction.  <code class="docutils literal notranslate"><span class="pre">label</span></code> stores the morphism label.</p>
<p>This works as follows (disregard the yet unexplained arguments):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories.diagram_drawing</span> <span class="kn">import</span> <span class="n">ArrowStringDescription</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">astr</span> <span class="o">=</span> <span class="n">ArrowStringDescription</span><span class="p">(</span>
<span class="gp">... </span><span class="n">unit</span><span class="o">=</span><span class="s2">&quot;mm&quot;</span><span class="p">,</span> <span class="n">curving</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">curving_amount</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="gp">... </span><span class="n">looping_start</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">looping_end</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">horizontal_direction</span><span class="o">=</span><span class="s2">&quot;d&quot;</span><span class="p">,</span>
<span class="gp">... </span><span class="n">vertical_direction</span><span class="o">=</span><span class="s2">&quot;r&quot;</span><span class="p">,</span> <span class="n">label_position</span><span class="o">=</span><span class="s2">&quot;_&quot;</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">astr</span><span class="p">))</span>
<span class="go">\ar[dr]_{f}</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">curving</span></code> should be one of <code class="docutils literal notranslate"><span class="pre">&quot;^&quot;</span></code>, <code class="docutils literal notranslate"><span class="pre">&quot;_&quot;</span></code> to specify in which
direction the arrow is going to curve. <code class="docutils literal notranslate"><span class="pre">curving_amount</span></code> is a number
describing how many <code class="docutils literal notranslate"><span class="pre">unit</span></code>’s the morphism is going to curve:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">astr</span> <span class="o">=</span> <span class="n">ArrowStringDescription</span><span class="p">(</span>
<span class="gp">... </span><span class="n">unit</span><span class="o">=</span><span class="s2">&quot;mm&quot;</span><span class="p">,</span> <span class="n">curving</span><span class="o">=</span><span class="s2">&quot;^&quot;</span><span class="p">,</span> <span class="n">curving_amount</span><span class="o">=</span><span class="mi">12</span><span class="p">,</span>
<span class="gp">... </span><span class="n">looping_start</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">looping_end</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">horizontal_direction</span><span class="o">=</span><span class="s2">&quot;d&quot;</span><span class="p">,</span>
<span class="gp">... </span><span class="n">vertical_direction</span><span class="o">=</span><span class="s2">&quot;r&quot;</span><span class="p">,</span> <span class="n">label_position</span><span class="o">=</span><span class="s2">&quot;_&quot;</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">astr</span><span class="p">))</span>
<span class="go">\ar@/^12mm/[dr]_{f}</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">looping_start</span></code> and <code class="docutils literal notranslate"><span class="pre">looping_end</span></code> are currently only used for
loop morphisms, those which have the same domain and codomain.
These two attributes should store a valid Xy-pic direction and
specify, correspondingly, the direction the arrow gets out into
and the direction the arrow gets back from:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">astr</span> <span class="o">=</span> <span class="n">ArrowStringDescription</span><span class="p">(</span>
<span class="gp">... </span><span class="n">unit</span><span class="o">=</span><span class="s2">&quot;mm&quot;</span><span class="p">,</span> <span class="n">curving</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">curving_amount</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="gp">... </span><span class="n">looping_start</span><span class="o">=</span><span class="s2">&quot;u&quot;</span><span class="p">,</span> <span class="n">looping_end</span><span class="o">=</span><span class="s2">&quot;l&quot;</span><span class="p">,</span> <span class="n">horizontal_direction</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span>
<span class="gp">... </span><span class="n">vertical_direction</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">label_position</span><span class="o">=</span><span class="s2">&quot;_&quot;</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">astr</span><span class="p">))</span>
<span class="go">\ar@(u,l)[]_{f}</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">label_displacement</span></code> controls how far the arrow label is from
the ends of the arrow.  For example, to position the arrow label
near the arrow head, use “&gt;”:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">astr</span> <span class="o">=</span> <span class="n">ArrowStringDescription</span><span class="p">(</span>
<span class="gp">... </span><span class="n">unit</span><span class="o">=</span><span class="s2">&quot;mm&quot;</span><span class="p">,</span> <span class="n">curving</span><span class="o">=</span><span class="s2">&quot;^&quot;</span><span class="p">,</span> <span class="n">curving_amount</span><span class="o">=</span><span class="mi">12</span><span class="p">,</span>
<span class="gp">... </span><span class="n">looping_start</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">looping_end</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">horizontal_direction</span><span class="o">=</span><span class="s2">&quot;d&quot;</span><span class="p">,</span>
<span class="gp">... </span><span class="n">vertical_direction</span><span class="o">=</span><span class="s2">&quot;r&quot;</span><span class="p">,</span> <span class="n">label_position</span><span class="o">=</span><span class="s2">&quot;_&quot;</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">astr</span><span class="o">.</span><span class="n">label_displacement</span> <span class="o">=</span> <span class="s2">&quot;&gt;&quot;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">astr</span><span class="p">))</span>
<span class="go">\ar@/^12mm/[dr]_&gt;{f}</span>
</pre></div>
</div>
<p>Finally, <code class="docutils literal notranslate"><span class="pre">arrow_style</span></code> is used to specify the arrow style.  To
get a dashed arrow, for example, use “{–&gt;}” as arrow style:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">astr</span> <span class="o">=</span> <span class="n">ArrowStringDescription</span><span class="p">(</span>
<span class="gp">... </span><span class="n">unit</span><span class="o">=</span><span class="s2">&quot;mm&quot;</span><span class="p">,</span> <span class="n">curving</span><span class="o">=</span><span class="s2">&quot;^&quot;</span><span class="p">,</span> <span class="n">curving_amount</span><span class="o">=</span><span class="mi">12</span><span class="p">,</span>
<span class="gp">... </span><span class="n">looping_start</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">looping_end</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">horizontal_direction</span><span class="o">=</span><span class="s2">&quot;d&quot;</span><span class="p">,</span>
<span class="gp">... </span><span class="n">vertical_direction</span><span class="o">=</span><span class="s2">&quot;r&quot;</span><span class="p">,</span> <span class="n">label_position</span><span class="o">=</span><span class="s2">&quot;_&quot;</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">astr</span><span class="o">.</span><span class="n">arrow_style</span> <span class="o">=</span> <span class="s2">&quot;{--&gt;}&quot;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">astr</span><span class="p">))</span>
<span class="go">\ar@/^12mm/@{--&gt;}[dr]_{f}</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>Instances of <a class="reference internal" href="#sympy.categories.diagram_drawing.ArrowStringDescription" title="sympy.categories.diagram_drawing.ArrowStringDescription"><code class="xref py py-class docutils literal notranslate"><span class="pre">ArrowStringDescription</span></code></a> will be constructed
by <a class="reference internal" href="#sympy.categories.diagram_drawing.XypicDiagramDrawer" title="sympy.categories.diagram_drawing.XypicDiagramDrawer"><code class="xref py py-class docutils literal notranslate"><span class="pre">XypicDiagramDrawer</span></code></a> and provided for further use in
formatters.  The user is not expected to construct instances of
<a class="reference internal" href="#sympy.categories.diagram_drawing.ArrowStringDescription" title="sympy.categories.diagram_drawing.ArrowStringDescription"><code class="xref py py-class docutils literal notranslate"><span class="pre">ArrowStringDescription</span></code></a> themselves.</p>
<p>To be able to properly utilise this class, the reader is encouraged
to checkout the Xy-pic user guide, available at [Xypic].</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.categories.diagram_drawing.XypicDiagramDrawer" title="sympy.categories.diagram_drawing.XypicDiagramDrawer"><code class="xref py py-obj docutils literal notranslate"><span class="pre">XypicDiagramDrawer</span></code></a></p>
</div>
<p class="rubric">References</p>
<p>[Xypic] <a class="reference external" href="http://xy-pic.sourceforge.net/">http://xy-pic.sourceforge.net/</a></p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.categories.diagram_drawing.XypicDiagramDrawer">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.categories.diagram_drawing.</span></span><span class="sig-name descname"><span class="pre">XypicDiagramDrawer</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/categories/diagram_drawing.py#L1507-L2517"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.categories.diagram_drawing.XypicDiagramDrawer" title="Permalink to this definition">¶</a></dt>
<dd><p>Given a <a class="reference internal" href="#sympy.categories.Diagram" title="sympy.categories.Diagram"><code class="xref py py-class docutils literal notranslate"><span class="pre">Diagram</span></code></a> and the corresponding
<a class="reference internal" href="#sympy.categories.diagram_drawing.DiagramGrid" title="sympy.categories.diagram_drawing.DiagramGrid"><code class="xref py py-class docutils literal notranslate"><span class="pre">DiagramGrid</span></code></a>, produces the Xy-pic representation of the
diagram.</p>
<p>The most important method in this class is <code class="docutils literal notranslate"><span class="pre">draw</span></code>.  Consider the
following triangle diagram:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span><span class="p">,</span> <span class="n">Diagram</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">DiagramGrid</span><span class="p">,</span> <span class="n">XypicDiagramDrawer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;C&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diagram</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">],</span> <span class="p">{</span><span class="n">g</span> <span class="o">*</span> <span class="n">f</span><span class="p">:</span> <span class="s2">&quot;unique&quot;</span><span class="p">})</span>
</pre></div>
</div>
<p>To draw this diagram, its objects need to be laid out with a
<a class="reference internal" href="#sympy.categories.diagram_drawing.DiagramGrid" title="sympy.categories.diagram_drawing.DiagramGrid"><code class="xref py py-class docutils literal notranslate"><span class="pre">DiagramGrid</span></code></a>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">grid</span> <span class="o">=</span> <span class="n">DiagramGrid</span><span class="p">(</span><span class="n">diagram</span><span class="p">)</span>
</pre></div>
</div>
<p>Finally, the drawing:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">drawer</span> <span class="o">=</span> <span class="n">XypicDiagramDrawer</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">drawer</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="n">diagram</span><span class="p">,</span> <span class="n">grid</span><span class="p">))</span>
<span class="go">\xymatrix{</span>
<span class="go">A \ar[d]_{g\circ f} \ar[r]^{f} &amp; B \ar[ld]^{g} \\</span>
<span class="go">C &amp;</span>
<span class="go">}</span>
</pre></div>
</div>
<p>For further details see the docstring of this method.</p>
<p>To control the appearance of the arrows, formatters are used.  The
dictionary <code class="docutils literal notranslate"><span class="pre">arrow_formatters</span></code> maps morphisms to formatter
functions.  A formatter is accepts an
<a class="reference internal" href="#sympy.categories.diagram_drawing.ArrowStringDescription" title="sympy.categories.diagram_drawing.ArrowStringDescription"><code class="xref py py-class docutils literal notranslate"><span class="pre">ArrowStringDescription</span></code></a> and is allowed to modify any of
the arrow properties exposed thereby.  For example, to have all
morphisms with the property <code class="docutils literal notranslate"><span class="pre">unique</span></code> appear as dashed arrows,
and to have their names prepended with <span class="math notranslate nohighlight">\(\exists !\)</span>, the following
should be done:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">formatter</span><span class="p">(</span><span class="n">astr</span><span class="p">):</span>
<span class="gp">... </span>  <span class="n">astr</span><span class="o">.</span><span class="n">label</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;\exists !&quot;</span> <span class="o">+</span> <span class="n">astr</span><span class="o">.</span><span class="n">label</span>
<span class="gp">... </span>  <span class="n">astr</span><span class="o">.</span><span class="n">arrow_style</span> <span class="o">=</span> <span class="s2">&quot;{--&gt;}&quot;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">drawer</span><span class="o">.</span><span class="n">arrow_formatters</span><span class="p">[</span><span class="s2">&quot;unique&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">formatter</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">drawer</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="n">diagram</span><span class="p">,</span> <span class="n">grid</span><span class="p">))</span>
<span class="go">\xymatrix{</span>
<span class="go">A \ar@{--&gt;}[d]_{\exists !g\circ f} \ar[r]^{f} &amp; B \ar[ld]^{g} \\</span>
<span class="go">C &amp;</span>
<span class="go">}</span>
</pre></div>
</div>
<p>To modify the appearance of all arrows in the diagram, set
<code class="docutils literal notranslate"><span class="pre">default_arrow_formatter</span></code>.  For example, to place all morphism
labels a little bit farther from the arrow head so that they look
more centred, do as follows:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">default_formatter</span><span class="p">(</span><span class="n">astr</span><span class="p">):</span>
<span class="gp">... </span>  <span class="n">astr</span><span class="o">.</span><span class="n">label_displacement</span> <span class="o">=</span> <span class="s2">&quot;(0.45)&quot;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">drawer</span><span class="o">.</span><span class="n">default_arrow_formatter</span> <span class="o">=</span> <span class="n">default_formatter</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">drawer</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="n">diagram</span><span class="p">,</span> <span class="n">grid</span><span class="p">))</span>
<span class="go">\xymatrix{</span>
<span class="go">A \ar@{--&gt;}[d]_(0.45){\exists !g\circ f} \ar[r]^(0.45){f} &amp; B \ar[ld]^(0.45){g} \\</span>
<span class="go">C &amp;</span>
<span class="go">}</span>
</pre></div>
</div>
<p>In some diagrams some morphisms are drawn as curved arrows.
Consider the following diagram:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;D&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;E&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">h</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">A</span><span class="p">,</span> <span class="s2">&quot;h&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">k</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;k&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diagram</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">,</span> <span class="n">h</span><span class="p">,</span> <span class="n">k</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">grid</span> <span class="o">=</span> <span class="n">DiagramGrid</span><span class="p">(</span><span class="n">diagram</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">drawer</span> <span class="o">=</span> <span class="n">XypicDiagramDrawer</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">drawer</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="n">diagram</span><span class="p">,</span> <span class="n">grid</span><span class="p">))</span>
<span class="go">\xymatrix{</span>
<span class="go">A \ar[r]_{f} &amp; B \ar[d]^{g} &amp; D \ar[l]^{k} \ar@/_3mm/[ll]_{h} \\</span>
<span class="go">&amp; C &amp;</span>
<span class="go">}</span>
</pre></div>
</div>
<p>To control how far the morphisms are curved by default, one can
use the <code class="docutils literal notranslate"><span class="pre">unit</span></code> and <code class="docutils literal notranslate"><span class="pre">default_curving_amount</span></code> attributes:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">drawer</span><span class="o">.</span><span class="n">unit</span> <span class="o">=</span> <span class="s2">&quot;cm&quot;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">drawer</span><span class="o">.</span><span class="n">default_curving_amount</span> <span class="o">=</span> <span class="mi">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">drawer</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="n">diagram</span><span class="p">,</span> <span class="n">grid</span><span class="p">))</span>
<span class="go">\xymatrix{</span>
<span class="go">A \ar[r]_{f} &amp; B \ar[d]^{g} &amp; D \ar[l]^{k} \ar@/_1cm/[ll]_{h} \\</span>
<span class="go">&amp; C &amp;</span>
<span class="go">}</span>
</pre></div>
</div>
<p>In some diagrams, there are multiple curved morphisms between the
same two objects.  To control by how much the curving changes
between two such successive morphisms, use
<code class="docutils literal notranslate"><span class="pre">default_curving_step</span></code>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">drawer</span><span class="o">.</span><span class="n">default_curving_step</span> <span class="o">=</span> <span class="mi">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">h1</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">D</span><span class="p">,</span> <span class="s2">&quot;h1&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diagram</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">,</span> <span class="n">h</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">h1</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">grid</span> <span class="o">=</span> <span class="n">DiagramGrid</span><span class="p">(</span><span class="n">diagram</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">drawer</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="n">diagram</span><span class="p">,</span> <span class="n">grid</span><span class="p">))</span>
<span class="go">\xymatrix{</span>
<span class="go">A \ar[r]_{f} \ar@/^1cm/[rr]^{h_{1}} &amp; B \ar[d]^{g} &amp; D \ar[l]^{k} \ar@/_2cm/[ll]_{h} \\</span>
<span class="go">&amp; C &amp;</span>
<span class="go">}</span>
</pre></div>
</div>
<p>The default value of <code class="docutils literal notranslate"><span class="pre">default_curving_step</span></code> is 4 units.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.categories.diagram_drawing.XypicDiagramDrawer.draw" title="sympy.categories.diagram_drawing.XypicDiagramDrawer.draw"><code class="xref py py-obj docutils literal notranslate"><span class="pre">draw</span></code></a>, <a class="reference internal" href="#sympy.categories.diagram_drawing.ArrowStringDescription" title="sympy.categories.diagram_drawing.ArrowStringDescription"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ArrowStringDescription</span></code></a></p>
</div>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.categories.diagram_drawing.XypicDiagramDrawer.draw">
<span class="sig-name descname"><span class="pre">draw</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">diagram</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">grid</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">masked</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">diagram_format</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/categories/diagram_drawing.py#L2393-L2517"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.categories.diagram_drawing.XypicDiagramDrawer.draw" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the Xy-pic representation of <code class="docutils literal notranslate"><span class="pre">diagram</span></code> laid out in
<code class="docutils literal notranslate"><span class="pre">grid</span></code>.</p>
<p>Consider the following simple triangle diagram.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span><span class="p">,</span> <span class="n">Diagram</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">DiagramGrid</span><span class="p">,</span> <span class="n">XypicDiagramDrawer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;C&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diagram</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">],</span> <span class="p">{</span><span class="n">g</span> <span class="o">*</span> <span class="n">f</span><span class="p">:</span> <span class="s2">&quot;unique&quot;</span><span class="p">})</span>
</pre></div>
</div>
<p>To draw this diagram, its objects need to be laid out with a
<a class="reference internal" href="#sympy.categories.diagram_drawing.DiagramGrid" title="sympy.categories.diagram_drawing.DiagramGrid"><code class="xref py py-class docutils literal notranslate"><span class="pre">DiagramGrid</span></code></a>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">grid</span> <span class="o">=</span> <span class="n">DiagramGrid</span><span class="p">(</span><span class="n">diagram</span><span class="p">)</span>
</pre></div>
</div>
<p>Finally, the drawing:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">drawer</span> <span class="o">=</span> <span class="n">XypicDiagramDrawer</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">drawer</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="n">diagram</span><span class="p">,</span> <span class="n">grid</span><span class="p">))</span>
<span class="go">\xymatrix{</span>
<span class="go">A \ar[d]_{g\circ f} \ar[r]^{f} &amp; B \ar[ld]^{g} \\</span>
<span class="go">C &amp;</span>
<span class="go">}</span>
</pre></div>
</div>
<p>The argument <code class="docutils literal notranslate"><span class="pre">masked</span></code> can be used to skip morphisms in the
presentation of the diagram:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">drawer</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="n">diagram</span><span class="p">,</span> <span class="n">grid</span><span class="p">,</span> <span class="n">masked</span><span class="o">=</span><span class="p">[</span><span class="n">g</span> <span class="o">*</span> <span class="n">f</span><span class="p">]))</span>
<span class="go">\xymatrix{</span>
<span class="go">A \ar[r]^{f} &amp; B \ar[ld]^{g} \\</span>
<span class="go">C &amp;</span>
<span class="go">}</span>
</pre></div>
</div>
<p>Finally, the <code class="docutils literal notranslate"><span class="pre">diagram_format</span></code> argument can be used to
specify the format string of the diagram.  For example, to
increase the spacing by 1 cm, proceeding as follows:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">drawer</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="n">diagram</span><span class="p">,</span> <span class="n">grid</span><span class="p">,</span> <span class="n">diagram_format</span><span class="o">=</span><span class="s2">&quot;@+1cm&quot;</span><span class="p">))</span>
<span class="go">\xymatrix@+1cm{</span>
<span class="go">A \ar[d]_{g\circ f} \ar[r]^{f} &amp; B \ar[ld]^{g} \\</span>
<span class="go">C &amp;</span>
<span class="go">}</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.categories.diagram_drawing.xypic_draw_diagram">
<span class="sig-prename descclassname"><span class="pre">sympy.categories.diagram_drawing.</span></span><span class="sig-name descname"><span class="pre">xypic_draw_diagram</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">diagram</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">masked</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">diagram_format</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">groups</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">hints</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/categories/diagram_drawing.py#L2520-L2558"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.categories.diagram_drawing.xypic_draw_diagram" title="Permalink to this definition">¶</a></dt>
<dd><p>Provides a shortcut combining <a class="reference internal" href="#sympy.categories.diagram_drawing.DiagramGrid" title="sympy.categories.diagram_drawing.DiagramGrid"><code class="xref py py-class docutils literal notranslate"><span class="pre">DiagramGrid</span></code></a> and
<a class="reference internal" href="#sympy.categories.diagram_drawing.XypicDiagramDrawer" title="sympy.categories.diagram_drawing.XypicDiagramDrawer"><code class="xref py py-class docutils literal notranslate"><span class="pre">XypicDiagramDrawer</span></code></a>.  Returns an Xy-pic presentation of
<code class="docutils literal notranslate"><span class="pre">diagram</span></code>.  The argument <code class="docutils literal notranslate"><span class="pre">masked</span></code> is a list of morphisms which
will be not be drawn.  The argument <code class="docutils literal notranslate"><span class="pre">diagram_format</span></code> is the
format string inserted after “xymatrix”.  <code class="docutils literal notranslate"><span class="pre">groups</span></code> should be a
set of logical groups.  The <code class="docutils literal notranslate"><span class="pre">hints</span></code> will be passed directly to
the constructor of <a class="reference internal" href="#sympy.categories.diagram_drawing.DiagramGrid" title="sympy.categories.diagram_drawing.DiagramGrid"><code class="xref py py-class docutils literal notranslate"><span class="pre">DiagramGrid</span></code></a>.</p>
<p>For more information about the arguments, see the docstrings of
<a class="reference internal" href="#sympy.categories.diagram_drawing.DiagramGrid" title="sympy.categories.diagram_drawing.DiagramGrid"><code class="xref py py-class docutils literal notranslate"><span class="pre">DiagramGrid</span></code></a> and <code class="docutils literal notranslate"><span class="pre">XypicDiagramDrawer.draw</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span><span class="p">,</span> <span class="n">Diagram</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">xypic_draw_diagram</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;C&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diagram</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">],</span> <span class="p">{</span><span class="n">g</span> <span class="o">*</span> <span class="n">f</span><span class="p">:</span> <span class="s2">&quot;unique&quot;</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">xypic_draw_diagram</span><span class="p">(</span><span class="n">diagram</span><span class="p">))</span>
<span class="go">\xymatrix{</span>
<span class="go">A \ar[d]_{g\circ f} \ar[r]^{f} &amp; B \ar[ld]^{g} \\</span>
<span class="go">C &amp;</span>
<span class="go">}</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.categories.diagram_drawing.XypicDiagramDrawer" title="sympy.categories.diagram_drawing.XypicDiagramDrawer"><code class="xref py py-obj docutils literal notranslate"><span class="pre">XypicDiagramDrawer</span></code></a>, <a class="reference internal" href="#sympy.categories.diagram_drawing.DiagramGrid" title="sympy.categories.diagram_drawing.DiagramGrid"><code class="xref py py-obj docutils literal notranslate"><span class="pre">DiagramGrid</span></code></a></p>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.categories.diagram_drawing.preview_diagram">
<span class="sig-prename descclassname"><span class="pre">sympy.categories.diagram_drawing.</span></span><span class="sig-name descname"><span class="pre">preview_diagram</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">diagram</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">masked</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">diagram_format</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">groups</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">output</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'png'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">viewer</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">euler</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">hints</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/categories/diagram_drawing.py#L2561-L2592"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.categories.diagram_drawing.preview_diagram" title="Permalink to this definition">¶</a></dt>
<dd><p>Combines the functionality of <code class="docutils literal notranslate"><span class="pre">xypic_draw_diagram</span></code> and
<code class="docutils literal notranslate"><span class="pre">sympy.printing.preview</span></code>.  The arguments <code class="docutils literal notranslate"><span class="pre">masked</span></code>,
<code class="docutils literal notranslate"><span class="pre">diagram_format</span></code>, <code class="docutils literal notranslate"><span class="pre">groups</span></code>, and <code class="docutils literal notranslate"><span class="pre">hints</span></code> are passed to
<code class="docutils literal notranslate"><span class="pre">xypic_draw_diagram</span></code>, while <code class="docutils literal notranslate"><span class="pre">output</span></code>, <code class="docutils literal notranslate"><span class="pre">viewer,</span> <span class="pre">and</span> <span class="pre">``euler</span></code>
are passed to <code class="docutils literal notranslate"><span class="pre">preview</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">Object</span><span class="p">,</span> <span class="n">NamedMorphism</span><span class="p">,</span> <span class="n">Diagram</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.categories</span> <span class="kn">import</span> <span class="n">preview_diagram</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">Object</span><span class="p">(</span><span class="s2">&quot;C&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">NamedMorphism</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="s2">&quot;g&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="n">Diagram</span><span class="p">([</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">],</span> <span class="p">{</span><span class="n">g</span> <span class="o">*</span> <span class="n">f</span><span class="p">:</span> <span class="s2">&quot;unique&quot;</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">preview_diagram</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.categories.diagram_drawing.XypicDiagramDrawer" title="sympy.categories.diagram_drawing.XypicDiagramDrawer"><code class="xref py py-obj docutils literal notranslate"><span class="pre">XypicDiagramDrawer</span></code></a></p>
</div>
</dd></dl>

</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../index.html">
              <img class="logo" src="../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h3><a href="../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Category Theory</a><ul>
<li><a class="reference internal" href="#introduction">Introduction</a></li>
<li><a class="reference internal" href="#module-sympy.categories">Base Class Reference</a></li>
<li><a class="reference internal" href="#module-sympy.categories.diagram_drawing">Diagram Drawing</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="calculus/index.html"
                        title="previous chapter">Calculus</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="codegen.html"
                        title="next chapter">Code Generation</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/modules/categories.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="codegen.html" title="Code Generation"
             >next</a> |</li>
        <li class="right" >
          <a href="calculus/index.html" title="Calculus"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="index.html" >SymPy Modules Reference</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Category Theory</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/categories.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:24:05 GMT -->
</html>